package com.dyh.quickdemozwei.futureopreate;

import lombok.extern.slf4j.Slf4j;
import org.assertj.core.util.Lists;
@Slf4j
public class App {
    public static void main(String[] args) {
        DefaultOperateInspector inspector = new BootStrap()
                .queueNum(3)
                .groupWatchingNum(2)
                .wokerNum(2)
                .build();

        inspector.start();



        AbstractFutureOperate o1 = new AbstractFutureOperate() {
            @Override
            public Object work(Object param) {
                try {
                    Thread.sleep(1000L);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                setOutPut(1);
                log.info("o1完成");
                return 1;
            }
        };

        AbstractFutureOperate o2 = new AbstractFutureOperate() {
            @Override
            public Object work(Object param) {
                try {
                    Thread.sleep(1000L);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                log.info("o2完成");
                setOutPut(2);
                return 2;
            }
        };

        AbstractFutureOperate o3 = new AbstractFutureOperate() {
            @Override
            public Object work(Object param) {
                try {
                    Thread.sleep(1000L);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                log.info("o3完成");
                setOutPut(3);
                return 3;
            }
        };

        GroupFutureOperate groupFutureOperate = new GroupFutureOperate(
                Lists.newArrayList(o3,o2)
        );
        groupFutureOperate.addListener(new AbstractFutureOperate() {
            @Override
            public Object work(Object param) {
                log.info("groupFutureOperate 完成");
                return null;
            }
        });



        o1.addListener(new AbstractFutureOperate() {
            @Override
            public Object work(Object param) {
               log.info("o1 listener 完成");
                return null;

            }
        });


        inspector.add(o1);
        inspector.add(groupFutureOperate);




        try {
            inspector.hold();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
